package com.cisco.vsx.email.entities;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @author naresred
 *
 */
@Entity
@Table(name = "EMAIL_TEMPLATE_CONTENT")
public class EmailTemplateContentEntity implements Serializable {

	private static final long serialVersionUID = 9049562678503040368L;
	
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	@Column(name = "NAME", length = 100, nullable = false)
	private String name;
	
	@Column(name = "MIMETYPE", length = 100, nullable = false)
	private String mimeType;
	
	@Column(name = "ATTACHMENT", length = 1, nullable = false)
	private int attachment = 1;
	
	@Lob
	@Basic(fetch = FetchType.LAZY)
	@Column(name = "CONTENT", nullable = false)
	private byte[] content;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "TEMPLATEID", nullable = false)
	private EmailTemplateEntity emailTemplate;

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public byte[] getContent() {
		return content;
	}
	public void setContent(byte[] content) {
		this.content = content;
	}	

	public String getMimeType() {
		return mimeType;
	}
	public void setMimeType(String mimeType) {
		this.mimeType = mimeType;
	}
	
	public EmailTemplateEntity getEmailTemplate() {
		return emailTemplate;
	}
	public void setEmailTemplate(EmailTemplateEntity emailTemplate) {
		this.emailTemplate = emailTemplate;
	}	
	
	public int getAttachment() {
		return attachment;
	}
	public void setAttachment(int attachment) {
		this.attachment = attachment;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		EmailTemplateContentEntity other = (EmailTemplateContentEntity) obj;
		if (id != other.id) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}
	
	@Override
	public String toString() {
		return "EmailTemplateImage [id=" + id + ", name=" + name + ", emailTemplate=" + emailTemplate + "]";
	}	

}
